package com.mdinfo.gw.door.doorDriver.aopu.utils;

import com.alibaba.fastjson.JSON;
import com.mdinfo.base.utils.HttpUtil;
import com.mdinfo.base.utils.Md5Util;
import com.mdinfo.gw.door.doorDriver.aopu.request.BaseReq;
import com.mdinfo.gw.door.doorDriver.aopu.response.BaseResp;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/2/5.
 */
public class AopuUtil {

//    private static String url = "http://172.16.15.232:10000/doorDemo/aopu";
    private static String url = "http://172.16.15.172:8085";

    public static BaseResp send(BaseReq req){

        Map<String,String> headers = new HashMap<>();
        headers.put("Connection","close");
        HttpUtil.BoneHttpResponse response = HttpUtil.postForResponse(url, headers, md5(req));
        BaseResp resp = new BaseResp();
        resp.setHttpCode(response.getCode());
        return new BaseResp();
    }

    private static String md5(BaseReq req){
        String json = JSON.toJSONString(req);
        String md5 = Md5Util.md5(json);
        req.setMd5(md5);
        json = JSON.toJSONString(req);
        System.out.println(json);

        BaseReq baseReq = JSON.parseObject(json, BaseReq.class);

        return json;
    }
}
